package cminus;


import java.io.File;


public class AddFolderHandler implements AddHandler{

	@Override
	public void afterAdd(EditorFrame editorFrame, AddFrame addFrame, Object data) {
		TreeNode selectNode = editorFrame.getSelectionNode();	//获得树中所选取的节点
		File folder = selectNode.getFile();
		//如果folder不是一个目录，则用selectNode的父节点（是一个目录）做为新目录的父目录
		if(!folder.isDirectory())
		{
			TreeNode parent = (TreeNode)selectNode.getParent();
			selectNode = parent; //让当前所选文件的父目录作为当前选择的目录
			folder = parent.getFile();
		}
		File newFolder  = new File(folder.getAbsoluteFile()+File.separator+data);
		newFolder.mkdir();	//创建新的目录
		editorFrame.reloadNode(selectNode);
		editorFrame.setEnabled(true);
		addFrame.setVisible(false);
	}

}
